<?php

namespace app\YoucaiWeb\controller;
use app\YoucaiWeb\model\Node;
use think\Controller;
use think\Db;

class Base extends Controller
{
    public function _initialize()
    {
        if(!session('uid')||!session('username')){
            $this->redirect('login/index');
        }
        
        $auth = new \com\Auth();   
        $module     = strtolower(request()->module());
        $controller = strtolower(request()->controller());
        $action     = strtolower(request()->action());
        $url        = $module."/".$controller."/".$action;
        //跳过检测以及主页权限
        if(session('uid')!=1){
            if(!in_array($url, ['admin/index/index','admin/index/indexpage','admin/upload/upload','admin/index/uploadface'])){
                if(!$auth->check($url,session('uid'))){
                    $this->error('抱歉，您没有操作权限');
                }
            }
        }
        $node = new Node();
        $this->assign([
            'username' => session('username'),
            'portrait' => session('portrait'),
            'rolename' => session('rolename'),
            'menu' => $node->getMenu(session('rule'))
        ]);

        $config = Db::name('setup')->where('se_name',"bsta")->find();

        if($config['se_value'] == 0 && session('uid') !=1 ){
            $this->error('站点已经关闭，请稍后访问~');
        }
    }
}